package com.ymk.cmd;

import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.base.mybatis.Pagination;
import com.ymk.base.utlis.ParamsBuilder;
import com.ymk.bo.user.MchUserBO;
import com.ymk.core.code.cmd.UserCmdCode;
import com.ymk.service.IMchUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class MchUserListCmd extends ACmd {

    @Override
    public CmdSign executeSop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        MchUserBO reqData = super.getData(sign, MchUserBO.class);

        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
                .addParam("mobile", reqData.getMobile())
                .addParam("name", reqData.getName())
                .addParam("mobile", reqData.getMobile())
                .addParam("status",reqData.getStatus())
                .setReturnStruct(sign.getReturnStruct());

        Pagination pagination = sign.buildPage();
        pagination.setParams(paramsBuilder.build());

        List<MchUserBO> respDataList = this.MchUserService.listForPage(pagination);
        respSign.setPageInfo(pagination);

        respSign.setSource(super.getSource(respDataList));
        return respSign;
    }

    @Override
    public String getCmdCode() {
        return UserCmdCode.MCH_USER_LIST;
    }

    @Autowired
    private IMchUserService MchUserService;
}